package com.atguigu.dao.impl;

import com.atguigu.dao.ServerTypeDao;
import com.atguigu.pojo.ServerType;

import java.util.List;

public class ServerTypeDaoImpl extends BaseDao implements ServerTypeDao {

    @Override
    public int addServerType(ServerType serverType) {
        System.out.println("ServerTypeDaoImpl程序在["+Thread.currentThread().getName()+"]线程中");
        String sql="insert into t_serverType(`id`,`name`) values(?,?);";
        return update(sql,serverType.getId(),serverType.getName());
    }

    @Override
    public int deleteServerTypeById(String id) {
        String sql="delete from t_serverType where id=?";
        return update(sql,id);
    }

    @Override
    public int updateServerType(ServerType serverType) {
        String sql="update t_serverType set `name`=? where id=?";
        return update(sql,serverType.getName(),serverType.getId());
    }


    @Override
    public ServerType queryServerTypeById(String id) {
        String sql ="select `id`,`name` from t_serverType where id=?";
        return queryForOne(ServerType.class,sql,id);
    }
    @Override
    public ServerType queryServerTypeByName(String name){
        String sql ="select `id`,`name` from t_serverType where name=?";
        return queryForOne(ServerType.class,sql,name);
    }

    @Override
    public List<ServerType> queryServerTypes() {// 查询全部
        String sql ="select `id`,`name` from t_serverType";
        return queryForList(ServerType.class,sql);
    }

    @Override
    public Integer queryForPageTotalCount() {//查询总条目数,为page分片做准备
        String sql="select count(*) from t_serverType";
        Number serverTypeCount=(Number) queryForSingleValue(sql);//这个语句似乎可以返回任何类型的查询
        //System.out.println(bookCount);
        return serverTypeCount.intValue();
    }

    @Override
    public List<ServerType> queryForPageItems(Integer begin, Integer pageSize) {
        String sql="select `id`,`name` from t_serverType limit ?,?";
        return queryForList(ServerType.class,sql,begin,pageSize);//查询数据片段
    }
}
